<?php
class Dealscombined_Crawlers_Kgb_SiteProcessor extends Dealscombined_SiteProcessor_ProcessorAbstract
{
						
	private function getProducDetails()
	{
		/*$xml = $this->getXML($this->_feedPath);	
				
		foreach ($xml->product as $product){
			$data = array(
				'merchant_name'      => $product->programName,
				'merchant_id'        => $product->programId,	
				'merchant_logo'		 => $product->programLogoPath,		
				'aw_product_id'      => $product->TDProductId,
				'sku'                => $product->sku,
				'merchant_product_id'=> '',
				'product_name'       => $product->name,
				'short_description'  => $product->shortDescription,
				'description'        => $product->description,
				'category_id'        => $product->TDCategoryID,
				'category_name'      => $product->TDCategoryName,
				'merchant_category'  => $product->merchantCategoryName,
				'deep_link'          => $product->productUrl,
				'image_url'          => $product->imageUrl,
				'search_price'       => '',
				'currency'           => $product->currency,
				'delivery_cost'      => $product->shippingCost,
				'merchant_deep_link' => $product->uri->mLink,
				'merchant_image_url' => $product->uri->mImage,
				'thumbnail_url'       => $product->uri->awThumb,
				'brand_id'           => '',
				'brand_name'         => $product->brand,
				'commission_amount'  => $product->comAmount,
				'commission_group'   => $product->comGroup,
				'condition'          => $product->condition,
				'delivery_time'      => $product->deliveryTime,
				'price'              => $product->price,
				'ean'                => $product->ean,
				'in_stock'           => $product->inStock,
				'is_hotpick'         => '',
				'isbn'               => $product->isbn,
				'is_for_sale'        => '',
				'language'           => '',
				'merchant_thumb_url' => '',
				'model_number'       => $product->model,
				'mpn'                => $product->mpn,
				'parent_product_id'  => '',
				'pre_order'          => $product['pre_order'],
				'product_type'       => '',
				'promotional_text'   => $product->promoText,
				'rrp_price'          => $product->previousPrice,
				'specifications'     => $product->text->spec,
				'stock_quantity'     => $product->availability,
				'store_price'        => $product->price->store,
				'upc'                => $product->upc,
				'valid_from'         => $product->valFrom,
				'valid_to'           => $product->valTo,
				'warranty'           => $product->warranty,
				'web_offer'          => $product['web_offer'],
				'location'           => $product->fields->ThumbnailImage
			);			
			
			try{
				$this->_database->insert('products_temp', $data);
			}catch(Exception $e){
				echo 'Error with Db: '.$e->getMessage().PHP_EOL;
			}
		}	*/
		
		$xml = $this->getXML($this->_feedPath);

		foreach ($xml->merchant as $merchants) {
			//var_dump($merchants);
			foreach ($merchants->prod as $product) {
				$data = array(
					'merchant_name' => $merchants['name'],
					'merchant_id' => $merchants['id'],
					'network_product_id' => $product['id'],
					'merchant_product_id' => $product->pId,
					'product_name' => $product->text->name,
					'description' => $product->text->desc,
					'category_id' => $product->cat->awCatId,
					'category_name' => $product->cat->awCat,
					'merchant_category' => $product->cat->mCat,
					'deep_link' => $product->uri->awTrack,
					'image_url' => $product->uri->awImage,
					'search_price' => '',
					'currency' => $product->price['curr'],
					'delivery_cost' => $product->price->delivery,
					'merchant_deep_link' => $product->uri->mLink,
					'merchant_image_url' => $product->uri->mImage,
					'thumbnail_url' => $product->uri->awThumb,
					'brand_id' => '',
					'brand_name' => $product->brand->brandName,
					'commission_amount' => $product->comAmount,
					'commission_group' => $product->comGroup,
					'condition' => '',
					'delivery_time' => '',
					'price' => $product->price->buynow,
					'ean' => $product->ean,
					'in_stock' => $product['in_stock'],
					'is_hotpick' => '',
					'isbn' => $product->isbn,
					'is_for_sale' => '',
					'language' => '',
					'merchant_thumb_url' => $product->uri->mThumb,
					'model_number' => '',
					'mpn' => $product->mpn,
					'parent_product_id' => '',
					'pre_order' => $product['pre_order'],
					'product_type' => '',
					'promotional_text' => $product->text->promo,
					'rrp_price' => $product->price->rrp,
					'specifications' => $product->text->spec,
					'stock_quantity' => '',
					'store_price' => $product->price->store,
					'upc' => $product->upc,
					'valid_from' => $product->valFrom,
					'valid_to' => $product->valTo,
					'warranty' => $product->text->warranty,
					'web_offer' => $product['web_offer'],
				);

				try {
					$this->_database->insert('products_temp', $data);
				} catch(Exception $e) {
					echo 'Error with Db: ' . $e->getMessage() . PHP_EOL;
				}
			}
		}	
	}

	
	public function process($userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)')
	{
		echo 'Starting Time for '.get_class($this).' Product Details:'. date("Y-m-d H:i:s") . PHP_EOL;
		$this->getProducDetails();
		echo 'Finishing Time: '.date("Y-m-d H:i:s").PHP_EOL;
	}	
}			

